package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.ClassMapper;
import com.itheima.pojo.Class;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {
    @Autowired
    ClassMapper classMapper;


    @Override
    public List<Class> list() {
        return classMapper.list();
    }

    @Override
    public void delete(List<Integer> ids)  {
            classMapper.delete(ids);
    }

    @Override
    public void add(Class clazz) {

            clazz.setCreateTime(LocalDateTime.now());
            clazz.setUpdateTime(LocalDateTime.now());

            classMapper.insert(clazz);

    }

    @Override
    public Emp[] findByJobId(Short jobId) {
        return new Emp[0];
    }

    @Override
    public Class[] findByClassName(String className) {
        return new Class[0];
    }

    @Override
    public Class[] findByEndTime(LocalDateTime startTime, LocalDateTime endTime) {
        return new Class[0];
    }

    @Override
    public void update(Class c)  {
        classMapper.update(c);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, LocalDate begin, LocalDate end) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);

        //2. 执行查询
        List<Class> classList = classMapper.list(name, begin, end);
        Page<Class> p = (Page<Class>) classList;

        //3. 封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;

    }
}
